<?php 
session_start(); 
require_once('include/connect.inc.php'); 
//-------แบ่งหน้า--------

$strSQL = "SELECT * FROM tb_news";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$Num_Rows = mysql_num_rows($objQuery);
$Per_Page = 3;   //Per Page

$Page = $_GET["Page"];
if(!$_GET["Page"])
{
	$Page=1;
}

$Prev_Page = $Page-1;
$Next_Page = $Page+1;

$Page_Start = (($Per_Page*$Page)-$Per_Page);
if($Num_Rows<=$Per_Page)
{
	$Num_Pages =1;
}
else if(($Num_Rows % $Per_Page)==0)
{
	$Num_Pages =($Num_Rows/$Per_Page) ;
}
else
{
	$Num_Pages =($Num_Rows/$Per_Page)+1;
	$Num_Pages = (int)$Num_Pages;
}
	
$strSQL .=" order  by news_id DESC LIMIT $Page_Start , $Per_Page";
$objQuery  = mysql_query($strSQL);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Model Test Program</title>
<link rel="stylesheet" type="text/css" href="template/template_style_wood.css">
</head>

<dody>
<div id="menu"><div><img src="../images/icon-m.png" /></div>
<div id="menulinks">
		<a class="active" href="index.php">หน้าหลัก</a>
		<a href="login.php">เข้าสู่ระบบ</a>
		</div></div>
 
<div id="p3">    
	<div id="header"></div>
    	<div id="page">
    		<div id="p1"><font size="+3">ประกาศข่าวสาร</font>
<form> 
<?php
$count=(($Page-1)*$Per_Page)+1;
	while($objResult = mysql_fetch_array($objQuery)){
	?>
		<div class="p21"><?php echo $count; echo ". ";?><u><?=$objResult["news_topic"];?></u></div>
        <div class="p22"><font size="+2"><?=$objResult["news_detail"];?></font></div>
        <div class="p21"><font size="+1" color="#FF0000">ประกาศโดย : <?php echo $objResult["news_creator"]?>
		- วันที่ประกาศ :<?php echo $objResult["news_date"];?></font></div><hr />  
</form>
<?php
$count++;
}
?>   
            
<!--แบ่งหน้า-->
<font size="+1">ทั้งหมด <?php echo $Num_Rows;?> หัวข้อ : <?php echo $Num_Pages;?> หน้า :
<?php
	if($Prev_Page)
		{
			echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'><< ก่อนหน้า</a> ";
		}

		for($i=1; $i<=$Num_Pages; $i++){
			if($i != $Page)
			{
				echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i'>$i</a> ]";
			}
			else
			{
				echo "<b> $i </b>";
			}
		}
		if($Page!=$Num_Pages)
		{
			echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page'>ถัดไป>></a> ";
		}
		?>
        </font>
    </div>
    </div>
<div id="footer"></div>
</div>
</body>
</html>
